package com.aerors.Util;

import org.gdal.gdal.Dataset;

public class ImageUtils {

	public static int[] calcRGB(float elevation) {
		int[] rgb = new int[3];
		for (int r = 0; r < 256; r++) {
			for (int g = 0; g < 256; g++) {
				for (int b = 0; b < 256; b++) {
					if ((r * 256 * 256 + g * 256 + b) == (elevation + 10000) * 10) {
						rgb[0] = r;
						rgb[1] = g;
						rgb[2] = b;
						break;
					}
				}
			}
		}
		return rgb;
	}
	
	/**
	 * 根据gdal读取出的WKT坐标系信息获取坐标系的WKID
	 * 
	 * @param dataset
	 * @return
	 */
	public static String getImageWKID(Dataset dataset) {
		String crsStr = dataset.GetProjectionRef();
		System.out.println(crsStr);
		String epsgCode = "";
		// 坐标系描述不包含AUTHORITY项
		if (crsStr.indexOf("AUTHORITY") == -1) {
			if (crsStr.indexOf("WGS_1984_Web_Mercator_Auxiliary_Sphere") > -1) {
				epsgCode = "EPSG:3857";
			} else if (crsStr.indexOf("GCS_WGS_1984") > -1) {
				epsgCode = "EPSG:4326";
			}
		} else {
			epsgCode = crsStr.substring(crsStr.lastIndexOf("EPSG"), crsStr.length()).replace(",", ":").replace("]", "")
					.replace("\"", "");
		}
		return epsgCode;
	}
	
}
